/*
 * Copyright (c) Modify by T C L on 2019.3.1.
 */

package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.Utils.StringUtil;
import com.egg.ylt.pojo.CouponEntity;
import com.egg.ylt.presenter.ICouponsPresenter;
import com.egg.ylt.view.ICouponsView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

public class CouponsPresenterImpl extends BasePresenter<ICouponsView> implements ICouponsPresenter {

    @Override
    public void getCouponList(String token, String companyId, String userId, String applyType, String shopId,
                              String cardId) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("memberCompanyId", userId);
        hashMap.put("companyId", companyId);
        hashMap.put("ticketType", "");//全部的优惠券
        hashMap.put("applyType", applyType);
        hashMap.put("orgId", shopId);
        hashMap.put("cardTimesId", cardId);
        RequestManager.getInstance().requestPostByAsyn(API.GET_COUPON_BY_ID, hashMap,
                new ReqCallBack<CouponEntity>() {

                    @Override
                    public void onReqSuccess(CouponEntity result) {
                        mView.dismissDialogLoading();
                        mView.getCouponList(result);
                    }

                    @Override
                    public void onFailure(String result) {
                        mView.dismissDialogLoading();
                        mView.showError(result);
                        CommonUtils.makeEventToast(mContext, result, false);
                    }

                    @Override
                    public void onReqFailed(ErrorBean error) {
                        mView.dismissDialogLoading();
                        mView.showException(error.toString());
                        CommonUtils.makeEventToast(mContext, error.getMsg(), false);
                    }
                });
    }
}
